package main.chapter4

const val string = "Hello,world"

//返回函数
fun makeFun(): () -> Unit {
    var count = 0
    return fun() {
        println(++count)
    }
}

fun fibonacci(): () -> Long {
    var first = 0L
    var second = 1L
    return fun(): Long {
        val result = second
        second += first
        first = second - first
        return result
    }
}

fun add(x: Int) = fun(y: Int) = x + y

fun main(args: Array<String>) {
    val x = makeFun()
    x()
    x()
    x()
    val f = fibonacci()
    println(f())
    println(f())
    println(f())
    println(f())

    val add5 = add(5)
    println(add5(2)) //7
}